/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.google.code.smon.pers;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author xero
 */
@Entity
@Table(name = "server_status")
@NamedQueries({
    @NamedQuery(name = "ServerStatus.findAll", query = "SELECT s FROM ServerStatus s"),
    @NamedQuery(name = "ServerStatus.findById", query = "SELECT s FROM ServerStatus s WHERE s.id = :id"),
    @NamedQuery(name = "ServerStatus.findByServiceStatus", query = "SELECT s FROM ServerStatus s WHERE s.serviceStatus = :serviceStatus"),
    @NamedQuery(name = "ServerStatus.findByLatency", query = "SELECT s FROM ServerStatus s WHERE s.latency = :latency")})
public class ServerStatus implements Serializable {
    @Column(name = "last_checked")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastChecked;

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column(name = "service_status")
    private Boolean serviceStatus;
    @Column(name = "latency")
    private Integer latency;
    @JoinColumn(name = "id", referencedColumnName = "id", nullable = false, insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Server server;

    public ServerStatus() {
    }

    public ServerStatus(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Boolean getServiceStatus() {
        return serviceStatus;
    }

    public void setServiceStatus(Boolean serviceStatus) {
        this.serviceStatus = serviceStatus;
    }

    public Integer getLatency() {
        return latency;
    }

    public void setLatency(Integer latency) {
        this.latency = latency;
    }

    public Server getServer() {
        return server;
    }

    public void setServer(Server server) {
        this.server = server;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ServerStatus)) {
            return false;
        }
        ServerStatus other = (ServerStatus) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "online=" + getServiceStatus() + ",latency=" + getLatency();
    }

    public Date getLastChecked() {
        return lastChecked;
    }

    public void setLastChecked(Date lastChecked) {
        this.lastChecked = lastChecked;
    }
}
